<template>
  <a-card :bordered="false">

    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="7" :sm="8">
            <a-form-item label="敏感字" :label-col="{span: 6}" :wrapper-col="{span: 14, offset: 1}">
              <a-input v-model="queryParam.word" placeholder="请输入敏感字模糊检索" />
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="8">
            <a-form-item label="分类" :label-col="{span: 6}" :wrapper-col="{span: 14, offset: 1}">
              <ants-dict-select-tag v-model="queryParam.type" placeholder="请选择分类" dict-code="sensitive_word_type"/>
            </a-form-item>
          </a-col>
          <a-col :md="7" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator" style="border-top: 5px">
      <a-button type="primary" icon="plus" @click="handleAdd">添加</a-button>
    </div>

    <a-table
      ref="table"
      row-key="id"
      size="middle"
      :columns="columns"
      :data-source="dataSource"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      bordered
      class="j-table-force-nowrap"
    >
      <template slot="htmlSlot" slot-scope="text">
        <div v-html="text"/>
      </template>
      <span slot="introduce" slot-scope="text">
        <ants-ellipsis :value="text" :length="40"/>
      </span>
      <template slot="logo" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
        <img
          v-else
          :src="text"
          height="25px"
          alt=""
          style="max-width:80px;font-size: 12px;font-style: italic;"
        >
      </template>
      <span slot="action" slot-scope="text, record">
        <a @click="handleEdit(record)">
          <a-icon type="edit"/>
          编辑
        </a>
        <a-divider type="vertical"/>
        <a @click="handleDetail(record)">
          <a-icon type="eye"/>
          详情
        </a>
        <a-divider type="vertical"/>
        <a-popconfirm title="确定删除吗?" @confirm="() =>handleDelete(record.id)">
          <a>
            <a-icon type="delete"/>
            删除
          </a>
        </a-popconfirm>
      </span>
    </a-table>

    <sensitive-word-modal ref="modalForm" @ok="modalFormOk"/>

  </a-card>
</template>

<script>
import {TableListMixin} from '@/mixins/TableListMixin'
import SensitiveWordModal from './modules/SensitiveWordModal'
import {filterObj} from '@/utils/util'
import AntsEllipsis from '@/components/ants/AntsEllipsis'
import AntsDictSelectTag from '@/components/dict/AntsDictSelectTag'

export default {
  name: 'TechnologyStack',
  components: {
    SensitiveWordModal,
    AntsEllipsis,
    AntsDictSelectTag
  },
  mixins: [TableListMixin],
  data() {
    return {
      description: '技术栈',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 120,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '敏感字',
          align: 'center',
          dataIndex: 'word'
        },
        {
          title: '分类',
          align: 'center',
          dataIndex: 'type_dictText',
        },
        {
          title: '替换符',
          align: 'center',
          dataIndex: 'repl',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: '10%',
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: '/sensitiveWord/list',
        delete: '/sensitiveWord/delete',
        deleteBatch: '/sensitiveWord/deleteBatch'
      }
    }
  },
  methods: {
    getQueryParams() {
      // 获取查询条件
      const param = Object.assign(this.queryParam, this.filters)
      param.field = this.getQueryField()
      param.pageNo = this.pagination.current
      param.pageSize = this.pagination.pageSize
      return filterObj(param)
    },
  }
}
</script>
